﻿<?php

class DefaultController extends Controller
{
	public  $layout = 'application.modules.admin.views.layouts.main'; 
	public $defaultAction = 'login';
	public function actionIndex()
	{
		$this->render('index');
	}
	public function actionLogin()
	{
		if(!Yii::app()->user->isGuest)
		{
			$this->redirect(Yii::app()->user->getReturnUrl());
		}
		$model = new LoginForm;
		if(isset($_POST['ajax']) && $_POST['ajax']==='login_form')
		{
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}
		if(isset($_POST["LoginForm"]))
		{
			$model->attributes = $_POST['LoginForm'];
			if($model->validate() && $model->login())
			{
				
			 $this->redirect(Yii::app()->user->getReturnUrl());

			}
		}
		$this->renderPartial('login',array('model'=>$model));
		
	}

	public function actionLogout()
	{
		Yii::app()->user->logout();
		$this->redirect(array('../admin/default/login'));
			
	}
}